
import moment from 'moment'
import DatePicker from 'vue-datepicker'
import { getStatisticsList, showMsg, setMenuType } from '../../../../../../vuex/action'
import getDatePickerOption from '../../../../../../util/date-picker-option'
export default {
  name: 'statistics-user-list',
  components: {
    'vue-date-picker': DatePicker
  },
  data() {
    return {
      datePickerOption: getDatePickerOption({
        format: 'YYYY-MM-DD'
      }),
      startDate: '',
      endDate: '',
      list: []
    }
  },
  vuex: {
    getters: {
      fresh: state => state.dataflowListNeedFresh,
      activityId: state => state.activityStoreId
    },
    actions: {
      xGetStatisticsList: getStatisticsList,
      xShowMsg: showMsg,
      xSetMenuType: setMenuType
    }
  },
  ready() {
    this.startDate = this.endDate = moment(new Date()).format('YYYY-MM-DD')
    this.xSetMenuType('activity')
    this.getList({})
  },
  methods: {
    getList({start=this.startDate, endDate = this.endDate}) {
      var param = {
        activityId: this.activityId,
        startDate: start,
        endDate: endDate
      }
      this.xGetStatisticsList(param)
        .then((data) => {
          this.list = data.list
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
    search() {
      this.getList({})
    }
  },
  watch: {
    fresh() {
      if (this.fresh) {
        this.getList({})
      }
    }
  }
}
